package com.fsds.crem.web.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.fsds.crem.core.constant.Globals;
import com.fsds.crem.web.entity.NodeInfo;
import com.fsds.crem.web.entity.StatisticReport;
import com.fsds.crem.web.service.SaleDailyReportService;
import com.fsds.crem.web.service.StatisticReportService;

@Controller
@RequestMapping("/statistic")
public class StatisticReportController {

	@Resource
	private StatisticReportService statisticReportService;
	@Resource
	private SaleDailyReportService saleDailyReportService;
	
	/**
	 * 
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/headOffice")
	public String headOffice(HttpServletRequest request,String reportType){
		
		// 日报
		if(Globals.REPORT_TYPE_YINFU_SALE_DAY.equals(reportType)){
			
			request.setAttribute("dataMap", statisticReportService.findTotalSaleEarningByDay());
		}
		// 周报
		else if(Globals.REPORT_TYPE_YINFU_SALE_WEEK.equals(reportType)){
			
			request.setAttribute("dataMap", statisticReportService.findTotalSaleEarningByWeek());
		}
		// 月报
		else if(Globals.REPORT_TYPE_YINFU_SALE_MONTH.equals(reportType)){
			
			request.setAttribute("dataMap", statisticReportService.findTotalSaleEarningByMonth());
		}
		
		return "statistic/headoffice";
	}
	
	/**
	 * 
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/area")
	public String area(HttpServletRequest request,String reportType){
		
		// 日报
		if(Globals.REPORT_TYPE_YINFU_SALE_DAY.equals(reportType)){
			
			request.setAttribute("dataMap", statisticReportService.findAreaSaleEarningByDay());
		}
		// 周报
		else if(Globals.REPORT_TYPE_YINFU_SALE_WEEK.equals(reportType)){
			
			request.setAttribute("dataMap", statisticReportService.findAreaSaleEarningByWeek());
		}
		// 月报
		else if(Globals.REPORT_TYPE_YINFU_SALE_MONTH.equals(reportType)){
			
			request.setAttribute("dataMap", statisticReportService.findAreaSaleEarningByMonth());
		}
		
		return "statistic/area";
	}
	
	/**
	 * 
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/singleNode")
	public String singleNode(HttpServletRequest request,String reportType,String nodeCode){
		
		// 所有门店信息
		List<NodeInfo> nodeList = saleDailyReportService.findNodeList();
		request.setAttribute("nodeList", nodeList);
		
		StatisticReport statisticReport = new StatisticReport();
		statisticReport.setNodeCode(nodeCode);
		
		// 日报
		if(Globals.REPORT_TYPE_YINFU_SALE_DAY.equals(reportType)){
			
			request.setAttribute("dataMap", statisticReportService.findOneNodeSaleEarningByDay(statisticReport));
		}
		// 周报
		else if(Globals.REPORT_TYPE_YINFU_SALE_WEEK.equals(reportType)){
			
			request.setAttribute("dataMap", statisticReportService.findOneNodeSaleEarningByWeek(statisticReport));
		}
		// 月报
		else if(Globals.REPORT_TYPE_YINFU_SALE_MONTH.equals(reportType)){
			
			request.setAttribute("dataMap", statisticReportService.findOneNodeSaleEarningByMonth(statisticReport));
		}
		
		return "statistic/singlenode";
	}
}
